package test;

public class functionz {
	/*******************************************************************************
	 * Software: functionz.java
	 * Version:  1.0
	 * Date:     Feb 14, 2010 10:37:12 AM
	 * License:  none specified yet.
	 * 
	 * it's all about how functions can be defined.
	 *
	 * PURPOSE:
	 * REQUIREMENTS WHAT ELSE IS NEEDED:
	 * TODO:
	 * FEATURES:
	 *******************************************************************************/

	public functionz() {

	}

	/** **/

	public static void main(String[] args)
	{
		stuff(); // calling function v1.0
		printOut(3,4,"print"); // calls function v1.1 because 3 parameters are given
		printOut(3,4); // calls function v1.2 because only 2 parameters are given
	}

	/** function v1.0 very basic function, does not take any input or return any data (void means = nothing.)
	 * it's a static function, which means no copies will be made of the this function.
	 * it can also not be overrided.
	 * statischen Funktionen (auch Klassenmethoden genannt), also mit Methoden, die ohne ein erzeugtes Objekt auskommen.
	 * **/
	static void stuff()
	{
		
	}
	
	/** function v1.1 function, that does take input of a specific type (two double, one String) input but does not return any data. (void) **/
	static void printOut( double a, double b, String c ) 
	{
		if(c == "print")
		{
			System.out.println( a+b ); // prints 7.0
		}
	}

	/** function v1.2 function, that does take input and returns data of type String
	 * the funny thing is, each function does not need a specific name... BUT a specific SIGNATURE!
	 * now the signature is made up of
	 * 1. the name of the function
	 * 2. the arguments that can be passed to this function.
	 * 
	 * the so called overloaded function is that a function with the same name as another function but with different parameters.
	 * java automatically decides what function to call, by examining what parameters are given to the function.
	 * **/
	static String printOut( double a, double b ) 
	{
		System.out.println( a+b ); // prints 7.0
		String RESULT = ""+(a+b);
		return RESULT;
	}

	/**
	 * In contrast to other languages (AS3 etc.) in Java it's not possible to define default values for a function.
	 * Generally speaking, a function should never be called if there's no data to pass to it.
	 * If you find yourself in such a situation, chances are you've planned something incorrectly.
	 * Those functions which conceivably require a default value are likely poorly implemented,
	 * and can probably be broken up into at least two functions - one which requires data,
	 * and one which doesn't. If it can't, then the mistake is elsewhere.
	 * @param a
	 * @return
	 * so this won't work:
		static String printOut( double a=1, double b=1 ) 
		{
			System.out.println( a+b ); // prints 2.0 per default.
			return ""+(a+b);
		}
	 **/

	/**
	Für Methoden mit Rückgabewert gilt ebenso wie für void-Methoden, dass es mehr als ein return geben kann. Nach der Abarbeitung von return geht es im Programmcode des Aufrufers wie bei den normalen void-Methoden weiter.
	Beispiel In if-Anweisungen mit weiteren else-if-Alternativen und Rücksprung ist die Semantik oft die gleiche, wenn das else-if durch ein einfaches if ersetzt wird. Der nachfolgende Programmcode zeigt das:
	**/
	static int MultipleSchoiss( int a )
	{
		if ( a == 1 ) 
			return 0; 
		else if ( a == 2 ) 
			return 1;
		else if ( a == 3 ) 
			return 0; 
		else if ( a == 4 ) 
			return 1;
		else
			return 0;
	}

	static int lastBitSet( int i ) 
	{ 
		switch ( i & 1 ) { 
			case 0:
				return 0;
			case 1:
				return 1;
			default:
				return 0;
	  } 
	}

}